package com.ruoyi.ombanner.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ombanner.domain.OmBanner;
import com.ruoyi.ombanner.service.IOmBannerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * banner管理Controller
 * 
 * @author ruoyi
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/om/banner")
public class OmBannerController extends BaseController
{
    @Autowired
    private IOmBannerService omBannerService;

    /**
     * 查询banner管理列表
     */
    @PreAuthorize("@ss.hasPermi('om:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmBanner omBanner)
    {
        startPage();
        List<OmBanner> list = omBannerService.selectOmBannerList(omBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner管理列表
     */
    @PreAuthorize("@ss.hasPermi('om:banner:export')")
    @Log(title = "banner管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmBanner omBanner)
    {
        List<OmBanner> list = omBannerService.selectOmBannerList(omBanner);
        ExcelUtil<OmBanner> util = new ExcelUtil<OmBanner>(OmBanner.class);
        util.exportExcel(response, list, "banner管理数据");
    }

    /**
     * 获取banner管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('om:banner:query')")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(omBannerService.selectOmBannerByBannerId(bannerId));
    }

    /**
     * 新增banner管理
     */
    @PreAuthorize("@ss.hasPermi('om:banner:add')")
    @Log(title = "banner管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmBanner omBanner)
    {
        return toAjax(omBannerService.insertOmBanner(omBanner));
    }

    /**
     * 修改banner管理
     */
    @PreAuthorize("@ss.hasPermi('om:banner:edit')")
    @Log(title = "banner管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmBanner omBanner)
    {
        return toAjax(omBannerService.updateOmBanner(omBanner));
    }

    /**
     * 删除banner管理
     */
    @PreAuthorize("@ss.hasPermi('om:banner:remove')")
    @Log(title = "banner管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(omBannerService.deleteOmBannerByBannerIds(bannerIds));
    }
}
